#!/usr/bin/env python
#!--*-- coding: utf-8 --*--
import numpy as np 
import matplotlib.pyplot as plt 

xl = [1, 2, 3, 4, 5, 6, 7]
yl = [1, 1, 2, 2, 2, 2, 2]

# P0, P1, P2 = np.array([[1.5, 1], [2, 1], [2.5, 1.5]])
P0, P1, P2 = np.array([[2, 1], [4, 2], [5, 2]])
# 二次贝塞尔曲线
P = lambda t: (1 - t)**2 * P0 + 2 * t * (1 - t) * P1 + t**2 * P2

points = np.array([P(t) for t in np.linspace(0, 1, 30)])
x, y = points[:, 0], points[:, 1]
# print(x.tolist())
# plt.plot(x, y, 'b-')
# print(len(points))

p0, p1, p2 = np.array([[1.5, 1], [2, 1], P(1/3.)])
p = lambda t: (1 - t)**2 * p0 + 2 * t * (1 - t) * p1 + t**2 * p2
fir_seg = np.array([p(t) for t in np.linspace(0, 1, 15)])
sec_seg = points[10:]
lx = [1, 1.5] + fir_seg[:, 0].tolist() + sec_seg[:, 0].tolist()  + [6, 7]
ly = [1, 1] + fir_seg[:, 1].tolist() + sec_seg[:, 1].tolist()  + [2, 2]
plt.plot(lx, ly, 'b-')

plt.plot(xl, yl,color="green")

# 三次B样条曲线

yl2 = [e+3 for e in yl]
plt.plot(xl, yl2,color="green")

plt.plot([0, 0], [8, 0],color="red")
plt.plot([0, 8], [8, 8],color="red")
plt.xlabel("X")
plt.ylabel("Y")
plt.title("Plot with 2 arbitrary Lines")
plt.show()